home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Basic Question on SWITCH
- Date: Fri, 26 Jan 1996 17:03:37 +0200
- Organization: Carelcomp Forest
- Message-ID: <3108ED49.987@cmt.lpr.mail.carel.fi>
- References: <4e4cu4$95f@vixen.cso.uiuc.edu> <4e8p6m$n8q@ns.RezoNet.NET>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Ray Dunn wrote:
- >
- > In referenced article, HOTARD says...
- > >I am just learning how to program in C, and I had a question about
- > >switch.[snip]
- > No, the only thing you can do is to give a series of different case
- > labels, like:
- >
- > switch (character)
- > {
- > case '0':
- > case '1':
- > case '2':
- > [etc]
- > case '9':
- > [process a digit here]
- > break;
- >
- > case 'a':
- > case 'b':
- > etc.
- >
- > default:
- > [none of the above]
- >
- > A switch is not a good choice for what you're trying to do - although
- > it might produce quite efficient code, the source is very verbose.[snip]
-
- If the task is just to test for a, say, digit (eg. char a = 'X'; is the character
- in a a digit?), then you could also use:
-
- if (strchr("0123456789", a))
- ... /* It was a digit, do something */
-
- With proper optimizer (inline intrinsinct) this would produce quite efficient
- code, too.
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-